package br.com.lh.urabuilder.view.base
{
	import br.com.lh.urabuilder.event.ClosePopupEvent;

	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;

	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;

	import mx.containers.TitleWindow;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;

	/**
	 * Base "abstract" class for popups containing a UraConfirmationBar.
	 * By defaults sets the cancel event to close the popup.
	 *
	 *
	 * @author Luiz Henrique
	 *
	 */
	public class APopUpConfirmationBarContainer extends TitleWindow implements ConfirmationBarContainer
	{

		public function APopUpConfirmationBarContainer()
		{
			showCloseButton=true;
			verticalScrollPolicy="auto";
			maxHeight=550;
			addEventListener(Event.CLOSE, closeEvent);
			addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
		}

		public function okEvent():CairngormEvent
		{
			return null;
		}

		protected function createButtons():void
		{
			var buttonBar:ConfirmationBar=new ConfirmationBar();
			buttonBar.holder=this;
			addChild(buttonBar);
		}

		public function cancelEvent():CairngormEvent
		{
			return new ClosePopupEvent(this);
		}

		public function closeEvent(event:CloseEvent):void
		{
			closePopup();
		}

		public function closePopup():void
		{
			PopUpManager.removePopUp(this);
		}

		private function keyDown(evt:KeyboardEvent):void
		{
			if (evt.charCode == Keyboard.ESCAPE)
			{
				this.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
			}
			if (evt.charCode == Keyboard.ENTER)
			{
				CairngormEventDispatcher.getInstance().dispatchEvent(okEvent());
				closePopup();
			}


		}

		public function get validatorArray():Array
		{
			return new Array();
		}


	}
}

